﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "GbmpModel.h"
#include "ISteppedViewSymbol.h"
#include "DbDataSchema.h"
#include "RegenDataSchema.h"
#include "ElementId.h"
#include "IModelViewEventHandler.h"
#include "IElementDeletionComponent.h"

namespace gcmp
{
    class IElement;
    class IDocument;
    class IGraphicsElementShape;
    class IModelView;
    class ISteppedSectionPlane;

    class GBMP_MODEL_EXPORT SteppedViewSymbol : public NdbObjectSchematic, public ISteppedViewSymbol
    {
        CANNOT_COPY_OR_ASSIGN(SteppedViewSymbol)
    private:
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, SteppedViewSymbol, gcmp::NdbObjectSchematic, 40F56D9E - 8398 - 46C8 - A3F7 - 3B02DE948000, gbmpmodel, ISteppedViewSymbol)
            DATA_TRANSIENT(IElement*, pOwnerElement)
            DATA(ElementId,StairViewId) //剖面视图Id
            DATA(ElementId,ModelViewId) //所在视图的id
            DATA_WITHOUT_CHECK_AND_SUPPORT(OwnerPtr<IModelViewEventHandler>, ModelViewEventHandler)
            DATA_REGEN(Bool, ModelViewRangeUpdated)
            DBOBJECT_DATA_END

    public:
        virtual ~SteppedViewSymbol() {}

#pragma region static methods
    public:
        static ISteppedViewSymbol* Create(IDocument *pDoc, const ElementId& idModelView, const ElementId& idStairView);
        std::vector<gcmp::ElementId> CreateAuxiliaryElements(gcmp::IModelView* pModelView) const;
     
        static gcmp::UniIdentity GetImplementationUid();
#pragma endregion static methods

#pragma region IExternalObject 接口
    public:
        virtual bool SetOwnerElement(IElement* pOwnerElement) override;
        virtual const IElement* GetOwnerElement() const override;
        virtual IElement* GetOwnerElement() override;

        virtual NdbObject* GetTopOwnerObject() const override;

        virtual void UpdateForWeakParentDeletion(const std::set<ElementId>& deletedElementIds) override;

        virtual void ReportParents(IElementParentReporter& reporter) const override;

        virtual bool FinishEditing() override;

#pragma endregion IExternalObject 接口

#pragma region IStairViewSymbol 接口
    public:
        virtual ElementId GetModelViewId() const override;
        ElementId GetStairViewId() const;
        virtual ElementId GetOwnerElementId() const override;

#pragma endregion IStairViewSymbol 接口

#pragma region 其他
    public:
        OwnerPtr<IGraphicsElementShape> CreateModelViewElementShape(const IModelView* pModelView) const;

        bool MakeTransform(const Matrix4d& matrix);

        void MarkChanged();

        IDocument* GetDocument() const;

        IModelView* GetSteppedView() const;
        void SetModelViewId(const ElementId& viewId) ;
        IModelView* GetModelView() const;
        const ISteppedSectionPlane* GetSteppedPlane() const;
        ISteppedSectionPlane* GetSteppedPlane();

#pragma endregion 其他

    private:
        void ResetSteppedView(const ISteppedSectionPlane* pSteppedPlane);
        void SetStairViewId(const ElementId& viewId);
        //bool SubscribeModelViewEvent();
        //bool UnsubscribeModelViewEvent();
    };
}
